/*
 * NewRandomGraphPanel.java
 * Created on Jul 20, 2010, 3:32:51 PM
 */

package org.bm.graphexplorer.components;

import org.bm.blaise.scio.graph.Graph;
import org.bm.blaise.scio.graph.RandomGraph;

/**
 *
 * @author elisha
 */
public class NewRandomGraphPanel extends javax.swing.JPanel {


    /** Creates new form NewRandomGraphPanel */
    public NewRandomGraphPanel() {
        initComponents();
    }

    /** @return graph corresponding to the current graph settings */
    public Graph<Integer> getInstance() {
        int order = basicP.getOrder();
        float prob = (Float) probEdgeS.getValue();
        int numEdge = (Integer) numEdgesS.getValue();
        boolean directed = basicP.getDirected();
        boolean byEdgeNumber = numRB.isSelected();
        return byEdgeNumber ? RandomGraph.getInstance(order, numEdge, directed)
                : RandomGraph.getInstance(order, prob, directed);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        edgeTypeBG = new javax.swing.ButtonGroup();
        basicP = new NewSimpleGraphPanel(30,100000,false);
        edgeP = new javax.swing.JPanel();
        numRB = new javax.swing.JRadioButton();
        numEdgesS = new javax.swing.JSpinner();
        probRB = new javax.swing.JRadioButton();
        probEdgeS = new javax.swing.JSpinner();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));
        add(basicP);

        edgeP.setBorder(javax.swing.BorderFactory.createTitledBorder("Edge Generation Method"));
        edgeP.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        edgeTypeBG.add(numRB);
        numRB.setSelected(true);
        numRB.setText("total # of edges:");
        edgeP.add(numRB);

        numEdgesS.setModel(new javax.swing.SpinnerNumberModel(30, 0, 100000, 1));
        numEdgesS.setToolTipText("Enter the number of edges in the resulting graph (0-100,000)");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, numRB, org.jdesktop.beansbinding.ELProperty.create("${selected}"), numEdgesS, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        edgeP.add(numEdgesS);

        edgeTypeBG.add(probRB);
        probRB.setText("probability per edge:");
        edgeP.add(probRB);

        probEdgeS.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(0.5f), Float.valueOf(0.0f), Float.valueOf(1.0f), Float.valueOf(0.1f)));
        probEdgeS.setToolTipText("Enter the probability of occurence for each edge in the resulting graph (0.00-1.00)");
        probEdgeS.setPreferredSize(new java.awt.Dimension(70, 22));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, probRB, org.jdesktop.beansbinding.ELProperty.create("${selected}"), probEdgeS, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        edgeP.add(probEdgeS);

        add(edgeP);

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.bm.graphexplorer.components.NewSimpleGraphPanel basicP;
    private javax.swing.JPanel edgeP;
    private javax.swing.ButtonGroup edgeTypeBG;
    private javax.swing.JSpinner numEdgesS;
    private javax.swing.JRadioButton numRB;
    private javax.swing.JSpinner probEdgeS;
    private javax.swing.JRadioButton probRB;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
